﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.ModBus
{
	/// <summary>
	/// Modbus-Tcp协议的客户端通讯类，方便的和服务器进行数据交互，支持标准的功能码，也支持扩展的功能码实现，地址采用富文本的形式，详细见备注说明<br />
	/// The client communication class of Modbus-Tcp protocol is convenient for data interaction with the server. It supports standard function codes and also supports extended function codes. 
	/// The address is in rich text. For details, see the remarks.
	/// </summary>
	/// <remarks>
	/// 本客户端支持的标准的modbus协议，Modbus-Tcp及Modbus-Udp内置的消息号会进行自增，地址支持富文本格式，具体参考示例代码。<br />
	/// 读取线圈，输入线圈，寄存器，输入寄存器的方法中的读取长度对商业授权用户不限制，内部自动切割读取，结果合并。
	/// </remarks>
	/// <example>
	/// 本客户端支持的标准的modbus协议，Modbus-Tcp及Modbus-Udp内置的消息号会进行自增，比如我们想要控制消息号在0-1000之间自增，不能超过一千，可以写如下的代码：
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Modbus\Modbus.cs" region="Sample1" title="序号示例" />
	/// <note type="important">
	/// 地址共可以携带3个信息，最完整的表示方式"s=2;x=3;100"，对应的modbus报文是 02 03 00 64 00 01 的前四个字节，站号，功能码，起始地址，下面举例
	/// </note>
	/// 当读写int, uint, float, double, long, ulong类型的时候，支持动态指定数据格式，也就是 DataFormat 信息，本部分内容为商业授权用户专有，感谢支持。<br />
	/// ReadInt32("format=BADC;100") 指示使用BADC的格式来解析byte数组，从而获得int数据，同时支持和站号信息叠加，例如：ReadInt32("format=BADC;s=2;100")
	/// <list type="definition">
	/// <item>
	///     <term>读取线圈</term>
	///     <description>ReadCoil("100")表示读取线圈100的值，ReadCoil("s=2;100")表示读取站号为2，线圈地址为100的值</description>
	/// </item>
	/// <item>
	///     <term>读取离散输入</term>
	///     <description>ReadDiscrete("100")表示读取离散输入100的值，ReadDiscrete("s=2;100")表示读取站号为2，离散地址为100的值</description>
	/// </item>
	/// <item>
	///     <term>读取寄存器</term>
	///     <description>ReadInt16("100")表示读取寄存器100的值，ReadInt16("s=2;100")表示读取站号为2，寄存器100的值</description>
	/// </item>
	/// <item>
	///     <term>读取输入寄存器</term>
	///     <description>ReadInt16("x=4;100")表示读取输入寄存器100的值，ReadInt16("s=2;x=4;100")表示读取站号为2，输入寄存器100的值</description>
	/// </item>
	/// </list>
	/// 对于写入来说也是一致的
	/// <list type="definition">
	/// <item>
	///     <term>写入线圈</term>
	///     <description>WriteCoil("100",true)表示读取线圈100的值，WriteCoil("s=2;100",true)表示读取站号为2，线圈地址为100的值</description>
	/// </item>
	/// <item>
	///     <term>写入寄存器</term>
	///     <description>Write("100",(short)123)表示写寄存器100的值123，Write("s=2;100",(short)123)表示写入站号为2，寄存器100的值123</description>
	/// </item>
	/// </list>
	/// 特殊说明部分：
	///  <list type="definition">
	/// <item>
	///     <term>01功能码</term>
	///     <description>ReadBool("100")</description>
	/// </item>
	/// <item>
	///     <term>02功能码</term>
	///     <description>ReadBool("x=2;100")</description>
	/// </item>
	/// <item>
	///     <term>03功能码</term>
	///     <description>Read("100")</description>
	/// </item>
	/// <item>
	///     <term>04功能码</term>
	///     <description>Read("x=4;100")</description>
	/// </item>
	/// <item>
	///     <term>05功能码</term>
	///     <description>Write("100", True)</description>
	/// </item>
	/// <item>
	///     <term>06功能码</term>
	///     <description>Write("100", (short)100);Write("100", (ushort)100)</description>
	/// </item>
	/// <item>
	///     <term>0F功能码</term>
	///     <description>Write("100", new bool[]{True})</description>
	/// </item>
	/// <item>
	///     <term>10功能码</term>
	///     <description>写入寄存器的方法出去上述06功能码的示例，如果写一个short想用10功能码：Write("100", new short[]{100})</description>
	/// </item>
	/// <item>
	///     <term>16功能码</term>
	///     <description>Write("100.2", True) 当写入bool值的方法里，地址格式变为字地址时，就使用16功能码，通过掩码的方式来修改寄存器的某一位，需要Modbus服务器支持，否则写入无效。</description>
	/// </item>
	/// </list>
	/// 基本的用法请参照下面的代码示例
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Modbus\Modbus.cs" region="Example1" title="Modbus示例" />
	/// </example>
	// Token: 0x020000D1 RID: 209
	public class ModbusTcpNet : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化一个Modbus-Tcp协议的客户端对象<br />
		/// Instantiate a client object of the Modbus-Tcp protocol
		/// </summary>
		// Token: 0x06000FF7 RID: 4087 RVA: 0x0005CB40 File Offset: 0x0005AD40
		public ModbusTcpNet()
		{
			this.softIncrementCount = new SoftIncrementCount(65535L, 0L, 1);
			base.WordLength = 1;
			this.station = 1;
			base.ByteTransform = new ReverseWordTransform();
		}

		/// <summary>
		/// 指定服务器地址，端口号，客户端自己的站号来初始化<br />
		/// Specify the server address, port number, and client's own station number to initialize
		/// </summary>
		/// <param name="ipAddress">服务器的Ip地址</param>
		/// <param name="port">服务器的端口号</param>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000FF8 RID: 4088 RVA: 0x0005CB94 File Offset: 0x0005AD94
		public ModbusTcpNet(string ipAddress, int port = 502, byte station = 1)
		{
			this.softIncrementCount = new SoftIncrementCount(65535L, 0L, 1);
			this.IpAddress = ipAddress;
			this.Port = port;
			base.WordLength = 1;
			this.station = station;
			base.ByteTransform = new ReverseWordTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000FF9 RID: 4089 RVA: 0x0005CBF6 File Offset: 0x0005ADF6
		protected override INetMessage GetNewNetMessage()
		{
			return new ModbusTcpMessage();
		}

		/// <inheritdoc />
		// Token: 0x06000FFA RID: 4090 RVA: 0x0005CC00 File Offset: 0x0005AE00
		protected override OperateResult InitializationOnConnect(Socket socket)
		{
			bool isUseAccountCertificate = this.isUseAccountCertificate;
			OperateResult result;
			if (isUseAccountCertificate)
			{
				result = base.AccountCertificate(socket);
			}
			else
			{
				result = base.InitializationOnConnect(socket);
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000FFB RID: 4091 RVA: 0x0005CC30 File Offset: 0x0005AE30
		[DebuggerStepThrough]
		protected override Task<OperateResult> InitializationOnConnectAsync(Socket socket)
		{
			ModbusTcpNet.<InitializationOnConnectAsync>d__7 <InitializationOnConnectAsync>d__ = new ModbusTcpNet.<InitializationOnConnectAsync>d__7();
			<InitializationOnConnectAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<InitializationOnConnectAsync>d__.<>4__this = this;
			<InitializationOnConnectAsync>d__.socket = socket;
			<InitializationOnConnectAsync>d__.<>1__state = -1;
			<InitializationOnConnectAsync>d__.<>t__builder.Start<ModbusTcpNet.<InitializationOnConnectAsync>d__7>(ref <InitializationOnConnectAsync>d__);
			return <InitializationOnConnectAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32(System.String,System.UInt16)" />
		// Token: 0x06000FFC RID: 4092 RVA: 0x0005CC7C File Offset: 0x0005AE7C
		[HslMqttApi("ReadInt32Array", "")]
		public override OperateResult<int[]> ReadInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<int[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32(System.String,System.UInt16)" />
		// Token: 0x06000FFD RID: 4093 RVA: 0x0005CCD8 File Offset: 0x0005AED8
		[HslMqttApi("ReadUInt32Array", "")]
		public override OperateResult<uint[]> ReadUInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<uint[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransUInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloat(System.String,System.UInt16)" />
		// Token: 0x06000FFE RID: 4094 RVA: 0x0005CD34 File Offset: 0x0005AF34
		[HslMqttApi("ReadFloatArray", "")]
		public override OperateResult<float[]> ReadFloat(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<float[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransSingle(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64(System.String,System.UInt16)" />
		// Token: 0x06000FFF RID: 4095 RVA: 0x0005CD90 File Offset: 0x0005AF90
		[HslMqttApi("ReadInt64Array", "")]
		public override OperateResult<long[]> ReadInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<long[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64(System.String,System.UInt16)" />
		// Token: 0x06001000 RID: 4096 RVA: 0x0005CDEC File Offset: 0x0005AFEC
		[HslMqttApi("ReadUInt64Array", "")]
		public override OperateResult<ulong[]> ReadUInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<ulong[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransUInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDouble(System.String,System.UInt16)" />
		// Token: 0x06001001 RID: 4097 RVA: 0x0005CE48 File Offset: 0x0005B048
		[HslMqttApi("ReadDoubleArray", "")]
		public override OperateResult<double[]> ReadDouble(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<double[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransDouble(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int32[])" />
		// Token: 0x06001002 RID: 4098 RVA: 0x0005CEA4 File Offset: 0x0005B0A4
		[HslMqttApi("WriteInt32Array", "")]
		public override OperateResult Write(string address, int[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt32[])" />
		// Token: 0x06001003 RID: 4099 RVA: 0x0005CED4 File Offset: 0x0005B0D4
		[HslMqttApi("WriteUInt32Array", "")]
		public override OperateResult Write(string address, uint[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Single[])" />
		// Token: 0x06001004 RID: 4100 RVA: 0x0005CF04 File Offset: 0x0005B104
		[HslMqttApi("WriteFloatArray", "")]
		public override OperateResult Write(string address, float[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int64[])" />
		// Token: 0x06001005 RID: 4101 RVA: 0x0005CF34 File Offset: 0x0005B134
		[HslMqttApi("WriteInt64Array", "")]
		public override OperateResult Write(string address, long[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt64[])" />
		// Token: 0x06001006 RID: 4102 RVA: 0x0005CF64 File Offset: 0x0005B164
		[HslMqttApi("WriteUInt64Array", "")]
		public override OperateResult Write(string address, ulong[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Double[])" />
		// Token: 0x06001007 RID: 4103 RVA: 0x0005CF94 File Offset: 0x0005B194
		[HslMqttApi("WriteDoubleArray", "")]
		public override OperateResult Write(string address, double[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32Async(System.String,System.UInt16)" />
		// Token: 0x06001008 RID: 4104 RVA: 0x0005CFC4 File Offset: 0x0005B1C4
		[DebuggerStepThrough]
		public override Task<OperateResult<int[]>> ReadInt32Async(string address, ushort length)
		{
			ModbusTcpNet.<ReadInt32Async>d__20 <ReadInt32Async>d__ = new ModbusTcpNet.<ReadInt32Async>d__20();
			<ReadInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<int[]>>.Create();
			<ReadInt32Async>d__.<>4__this = this;
			<ReadInt32Async>d__.address = address;
			<ReadInt32Async>d__.length = length;
			<ReadInt32Async>d__.<>1__state = -1;
			<ReadInt32Async>d__.<>t__builder.Start<ModbusTcpNet.<ReadInt32Async>d__20>(ref <ReadInt32Async>d__);
			return <ReadInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32Async(System.String,System.UInt16)" />
		// Token: 0x06001009 RID: 4105 RVA: 0x0005D018 File Offset: 0x0005B218
		[DebuggerStepThrough]
		public override Task<OperateResult<uint[]>> ReadUInt32Async(string address, ushort length)
		{
			ModbusTcpNet.<ReadUInt32Async>d__21 <ReadUInt32Async>d__ = new ModbusTcpNet.<ReadUInt32Async>d__21();
			<ReadUInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<uint[]>>.Create();
			<ReadUInt32Async>d__.<>4__this = this;
			<ReadUInt32Async>d__.address = address;
			<ReadUInt32Async>d__.length = length;
			<ReadUInt32Async>d__.<>1__state = -1;
			<ReadUInt32Async>d__.<>t__builder.Start<ModbusTcpNet.<ReadUInt32Async>d__21>(ref <ReadUInt32Async>d__);
			return <ReadUInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloatAsync(System.String,System.UInt16)" />
		// Token: 0x0600100A RID: 4106 RVA: 0x0005D06C File Offset: 0x0005B26C
		[DebuggerStepThrough]
		public override Task<OperateResult<float[]>> ReadFloatAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadFloatAsync>d__22 <ReadFloatAsync>d__ = new ModbusTcpNet.<ReadFloatAsync>d__22();
			<ReadFloatAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<float[]>>.Create();
			<ReadFloatAsync>d__.<>4__this = this;
			<ReadFloatAsync>d__.address = address;
			<ReadFloatAsync>d__.length = length;
			<ReadFloatAsync>d__.<>1__state = -1;
			<ReadFloatAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadFloatAsync>d__22>(ref <ReadFloatAsync>d__);
			return <ReadFloatAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64Async(System.String,System.UInt16)" />
		// Token: 0x0600100B RID: 4107 RVA: 0x0005D0C0 File Offset: 0x0005B2C0
		[DebuggerStepThrough]
		public override Task<OperateResult<long[]>> ReadInt64Async(string address, ushort length)
		{
			ModbusTcpNet.<ReadInt64Async>d__23 <ReadInt64Async>d__ = new ModbusTcpNet.<ReadInt64Async>d__23();
			<ReadInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<long[]>>.Create();
			<ReadInt64Async>d__.<>4__this = this;
			<ReadInt64Async>d__.address = address;
			<ReadInt64Async>d__.length = length;
			<ReadInt64Async>d__.<>1__state = -1;
			<ReadInt64Async>d__.<>t__builder.Start<ModbusTcpNet.<ReadInt64Async>d__23>(ref <ReadInt64Async>d__);
			return <ReadInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64Async(System.String,System.UInt16)" />
		// Token: 0x0600100C RID: 4108 RVA: 0x0005D114 File Offset: 0x0005B314
		[DebuggerStepThrough]
		public override Task<OperateResult<ulong[]>> ReadUInt64Async(string address, ushort length)
		{
			ModbusTcpNet.<ReadUInt64Async>d__24 <ReadUInt64Async>d__ = new ModbusTcpNet.<ReadUInt64Async>d__24();
			<ReadUInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<ulong[]>>.Create();
			<ReadUInt64Async>d__.<>4__this = this;
			<ReadUInt64Async>d__.address = address;
			<ReadUInt64Async>d__.length = length;
			<ReadUInt64Async>d__.<>1__state = -1;
			<ReadUInt64Async>d__.<>t__builder.Start<ModbusTcpNet.<ReadUInt64Async>d__24>(ref <ReadUInt64Async>d__);
			return <ReadUInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDoubleAsync(System.String,System.UInt16)" />
		// Token: 0x0600100D RID: 4109 RVA: 0x0005D168 File Offset: 0x0005B368
		[DebuggerStepThrough]
		public override Task<OperateResult<double[]>> ReadDoubleAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadDoubleAsync>d__25 <ReadDoubleAsync>d__ = new ModbusTcpNet.<ReadDoubleAsync>d__25();
			<ReadDoubleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<double[]>>.Create();
			<ReadDoubleAsync>d__.<>4__this = this;
			<ReadDoubleAsync>d__.address = address;
			<ReadDoubleAsync>d__.length = length;
			<ReadDoubleAsync>d__.<>1__state = -1;
			<ReadDoubleAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadDoubleAsync>d__25>(ref <ReadDoubleAsync>d__);
			return <ReadDoubleAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int32[])" />
		// Token: 0x0600100E RID: 4110 RVA: 0x0005D1BC File Offset: 0x0005B3BC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, int[] values)
		{
			ModbusTcpNet.<WriteAsync>d__26 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__26();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__26>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt32[])" />
		// Token: 0x0600100F RID: 4111 RVA: 0x0005D210 File Offset: 0x0005B410
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, uint[] values)
		{
			ModbusTcpNet.<WriteAsync>d__27 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__27();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__27>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Single[])" />
		// Token: 0x06001010 RID: 4112 RVA: 0x0005D264 File Offset: 0x0005B464
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, float[] values)
		{
			ModbusTcpNet.<WriteAsync>d__28 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__28();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__28>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int64[])" />
		// Token: 0x06001011 RID: 4113 RVA: 0x0005D2B8 File Offset: 0x0005B4B8
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, long[] values)
		{
			ModbusTcpNet.<WriteAsync>d__29 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__29();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__29>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt64[])" />
		// Token: 0x06001012 RID: 4114 RVA: 0x0005D30C File Offset: 0x0005B50C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ulong[] values)
		{
			ModbusTcpNet.<WriteAsync>d__30 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__30();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__30>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Double[])" />
		// Token: 0x06001013 RID: 4115 RVA: 0x0005D360 File Offset: 0x0005B560
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, double[] values)
		{
			ModbusTcpNet.<WriteAsync>d__31 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__31();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__31>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 获取或设置起始的地址是否从0开始，默认为True<br />
		/// Gets or sets whether the starting address starts from 0. The default is True
		/// </summary>
		/// <remarks>
		/// <note type="warning">因为有些设备的起始地址是从1开始的，就要设置本属性为<c>False</c></note>
		/// </remarks>
		// Token: 0x1700024B RID: 587
		// (get) Token: 0x06001014 RID: 4116 RVA: 0x0005D3B4 File Offset: 0x0005B5B4
		// (set) Token: 0x06001015 RID: 4117 RVA: 0x0005D3CC File Offset: 0x0005B5CC
		public bool AddressStartWithZero
		{
			get
			{
				return this.isAddressStartWithZero;
			}
			set
			{
				this.isAddressStartWithZero = value;
			}
		}

		/// <summary>
		/// 获取或者重新修改服务器的默认站号信息，当然，你可以再读写的时候动态指定，参见备注<br />
		/// Get or modify the default station number information of the server. Of course, you can specify it dynamically when reading and writing, see note
		/// </summary>
		/// <remarks>
		/// 当你调用 ReadCoil("100") 时，对应的站号就是本属性的值，当你调用 ReadCoil("s=2;100") 时，就忽略本属性的值，读写寄存器的时候同理
		/// </remarks>
		// Token: 0x1700024C RID: 588
		// (get) Token: 0x06001016 RID: 4118 RVA: 0x0005D3D8 File Offset: 0x0005B5D8
		// (set) Token: 0x06001017 RID: 4119 RVA: 0x0005D3F0 File Offset: 0x0005B5F0
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.Core.ByteTransformBase.DataFormat" />
		// Token: 0x1700024D RID: 589
		// (get) Token: 0x06001018 RID: 4120 RVA: 0x0005D3FC File Offset: 0x0005B5FC
		// (set) Token: 0x06001019 RID: 4121 RVA: 0x0005BAB1 File Offset: 0x00059CB1
		public DataFormat DataFormat
		{
			get
			{
				return base.ByteTransform.DataFormat;
			}
			set
			{
				base.ByteTransform.DataFormat = value;
			}
		}

		/// <summary>
		/// 字符串数据是否按照字来反转，默认为False<br />
		/// Whether the string data is reversed according to words. The default is False.
		/// </summary>
		/// <remarks>
		/// 字符串按照2个字节的排列进行颠倒，根据实际情况进行设置
		/// </remarks>
		// Token: 0x1700024E RID: 590
		// (get) Token: 0x0600101A RID: 4122 RVA: 0x0005D41C File Offset: 0x0005B61C
		// (set) Token: 0x0600101B RID: 4123 RVA: 0x0005BAE1 File Offset: 0x00059CE1
		public bool IsStringReverse
		{
			get
			{
				return base.ByteTransform.IsStringReverseByteWord;
			}
			set
			{
				base.ByteTransform.IsStringReverseByteWord = value;
			}
		}

		/// <summary>
		/// 获取modbus协议自增的消息号，你可以自定义modbus的消息号的规则，详细参见<see cref="T:HslCommunication.ModBus.ModbusTcpNet" />说明，也可以查找<see cref="T:HslCommunication.BasicFramework.SoftIncrementCount" />说明。<br />
		/// Get the message number incremented by the modbus protocol. You can customize the rules of the message number of the modbus. For details, please refer to the description of <see cref="T:HslCommunication.ModBus.ModbusTcpNet" />, or you can find the description of <see cref="T:HslCommunication.BasicFramework.SoftIncrementCount" />
		/// </summary>
		// Token: 0x1700024F RID: 591
		// (get) Token: 0x0600101C RID: 4124 RVA: 0x0005D439 File Offset: 0x0005B639
		public SoftIncrementCount MessageId
		{
			get
			{
				return this.softIncrementCount;
			}
		}

		/// <summary>
		/// 读取线圈，需要指定起始地址，如果富文本地址不指定，默认使用的功能码是 0x01<br />
		/// To read the coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x01.
		/// </summary>
		/// <param name="address">起始地址，格式为"1234"</param>
		/// <returns>带有成功标志的bool对象</returns>
		// Token: 0x0600101D RID: 4125 RVA: 0x0003AED6 File Offset: 0x000390D6
		public OperateResult<bool> ReadCoil(string address)
		{
			return this.ReadBool(address);
		}

		/// <summary>
		/// 批量的读取线圈，需要指定起始地址，读取长度，如果富文本地址不指定，默认使用的功能码是 0x01<br />
		/// For batch reading coils, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x01.
		/// </summary>
		/// <param name="address">起始地址，格式为"1234"</param>
		/// <param name="length">读取长度</param>
		/// <returns>带有成功标志的bool数组对象</returns>
		// Token: 0x0600101E RID: 4126 RVA: 0x0003AEDF File Offset: 0x000390DF
		public OperateResult<bool[]> ReadCoil(string address, ushort length)
		{
			return this.ReadBool(address, length);
		}

		/// <summary>
		/// 读取输入线圈，需要指定起始地址，如果富文本地址不指定，默认使用的功能码是 0x02<br />
		/// To read the input coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x02.
		/// </summary>
		/// <param name="address">起始地址，格式为"1234"</param>
		/// <returns>带有成功标志的bool对象</returns>
		// Token: 0x0600101F RID: 4127 RVA: 0x0005D441 File Offset: 0x0005B641
		public OperateResult<bool> ReadDiscrete(string address)
		{
			return ByteTransformHelper.GetResultFromArray<bool>(this.ReadDiscrete(address, 1));
		}

		/// <summary>
		/// 批量的读取输入点，需要指定起始地址，读取长度，如果富文本地址不指定，默认使用的功能码是 0x02<br />
		/// To read input points in batches, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x02
		/// </summary>
		/// <param name="address">起始地址，格式为"1234"</param>
		/// <param name="length">读取长度</param>
		/// <returns>带有成功标志的bool数组对象</returns>
		// Token: 0x06001020 RID: 4128 RVA: 0x0005D450 File Offset: 0x0005B650
		public OperateResult<bool[]> ReadDiscrete(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 2);
		}

		/// <summary>
		/// 从Modbus服务器批量读取寄存器的信息，需要指定起始地址，读取长度，如果富文本地址不指定，默认使用的功能码是 0x03，如果需要使用04功能码，那么地址就写成 x=4;100<br />
		/// To read the register information from the Modbus server in batches, you need to specify the start address and read length. If the rich text address is not specified, 
		/// the default function code is 0x03. If you need to use the 04 function code, the address is written as x = 4; 100
		/// </summary>
		/// <param name="address">起始地址，比如"100"，"x=4;100"，"s=1;100","s=1;x=4;100"</param>
		/// <param name="length">读取的数量</param>
		/// <returns>带有成功标志的字节信息</returns>
		/// <remarks>
		/// 富地址格式，支持携带站号信息，功能码信息，具体参照类的示例代码
		/// </remarks>
		/// <example>
		/// 此处演示批量读取的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Modbus\Modbus.cs" region="ReadExample1" title="Read示例" />
		/// </example>
		// Token: 0x06001021 RID: 4129 RVA: 0x0005D45C File Offset: 0x0005B65C
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				List<byte> list = new List<byte>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content[i], (ushort)this.softIncrementCount.GetCurrentValue()));
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					OperateResult<byte[]> operateResult3 = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult3);
					}
					list.AddRange(operateResult3.Content);
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			return result;
		}

		/// <summary>
		/// 将数据写入到Modbus的寄存器上去，需要指定起始地址和数据内容，如果富文本地址不指定，默认使用的功能码是 0x10<br />
		/// To write data to Modbus registers, you need to specify the start address and data content. If the rich text address is not specified, the default function code is 0x10
		/// </summary>
		/// <param name="address">起始地址，比如"100"，"x=4;100"，"s=1;100","s=1;x=4;100"</param>
		/// <param name="value">写入的数据，长度根据data的长度来指示</param>
		/// <returns>返回写入结果</returns>
		/// <remarks>
		/// 富地址格式，支持携带站号信息，功能码信息，具体参照类的示例代码
		/// </remarks>
		/// <example>
		/// 此处演示批量写入的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Modbus\Modbus.cs" region="WriteExample1" title="Write示例" />
		/// </example>
		// Token: 0x06001022 RID: 4130 RVA: 0x0005D548 File Offset: 0x0005B748
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <summary>
		/// 将数据写入到Modbus的单个寄存器上去，需要指定起始地址和数据值，如果富文本地址不指定，默认使用的功能码是 0x06<br />
		/// To write data to a single register of Modbus, you need to specify the start address and data value. If the rich text address is not specified, the default function code is 0x06.
		/// </summary>
		/// <param name="address">起始地址，比如"100"，"x=4;100"，"s=1;100","s=1;x=4;100"</param>
		/// <param name="value">写入的short数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06001023 RID: 4131 RVA: 0x0005D5C4 File Offset: 0x0005B7C4
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <summary>
		/// 将数据写入到Modbus的单个寄存器上去，需要指定起始地址和数据值，如果富文本地址不指定，默认使用的功能码是 0x06<br />
		/// To write data to a single register of Modbus, you need to specify the start address and data value. If the rich text address is not specified, the default function code is 0x06.
		/// </summary>
		/// <param name="address">起始地址，比如"100"，"x=4;100"，"s=1;100","s=1;x=4;100"</param>
		/// <param name="value">写入的ushort数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06001024 RID: 4132 RVA: 0x0005D640 File Offset: 0x0005B840
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <summary>
		/// 向设备写入掩码数据，使用0x16功能码，需要确认对方是否支持相关的操作，掩码数据的操作主要针对寄存器。<br />
		/// To write mask data to the server, using the 0x16 function code, you need to confirm whether the other party supports related operations. 
		/// The operation of mask data is mainly directed to the register.
		/// </summary>
		/// <param name="address">起始地址，起始地址，比如"100"，"x=4;100"，"s=1;100","s=1;x=4;100"</param>
		/// <param name="andMask">等待与操作的掩码数据</param>
		/// <param name="orMask">等待或操作的掩码数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06001025 RID: 4133 RVA: 0x0005D6BC File Offset: 0x0005B8BC
		[HslMqttApi("WriteMask", "")]
		public OperateResult WriteMask(string address, ushort andMask, ushort orMask)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteMaskModbusCommand(address, andMask, orMask, this.Station, this.AddressStartWithZero, 22);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Int16)" />
		// Token: 0x06001026 RID: 4134 RVA: 0x0005BE2A File Offset: 0x0005A02A
		public OperateResult WriteOneRegister(string address, short value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.UInt16)" />
		// Token: 0x06001027 RID: 4135 RVA: 0x0005BE34 File Offset: 0x0005A034
		public OperateResult WriteOneRegister(string address, ushort value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String)" />
		// Token: 0x06001028 RID: 4136 RVA: 0x0005D738 File Offset: 0x0005B938
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadCoilAsync(string address)
		{
			ModbusTcpNet.<ReadCoilAsync>d__57 <ReadCoilAsync>d__ = new ModbusTcpNet.<ReadCoilAsync>d__57();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadCoilAsync>d__57>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06001029 RID: 4137 RVA: 0x0005D784 File Offset: 0x0005B984
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadCoilAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadCoilAsync>d__58 <ReadCoilAsync>d__ = new ModbusTcpNet.<ReadCoilAsync>d__58();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.length = length;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadCoilAsync>d__58>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscrete(System.String)" />
		// Token: 0x0600102A RID: 4138 RVA: 0x0005D7D8 File Offset: 0x0005B9D8
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadDiscreteAsync(string address)
		{
			ModbusTcpNet.<ReadDiscreteAsync>d__59 <ReadDiscreteAsync>d__ = new ModbusTcpNet.<ReadDiscreteAsync>d__59();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadDiscreteAsync>d__59>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscrete(System.String,System.UInt16)" />
		// Token: 0x0600102B RID: 4139 RVA: 0x0005D824 File Offset: 0x0005BA24
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadDiscreteAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadDiscreteAsync>d__60 <ReadDiscreteAsync>d__ = new ModbusTcpNet.<ReadDiscreteAsync>d__60();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.length = length;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadDiscreteAsync>d__60>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Read(System.String,System.UInt16)" />
		// Token: 0x0600102C RID: 4140 RVA: 0x0005D878 File Offset: 0x0005BA78
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadAsync>d__61 <ReadAsync>d__ = new ModbusTcpNet.<ReadAsync>d__61();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadAsync>d__61>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Byte[])" />
		// Token: 0x0600102D RID: 4141 RVA: 0x0005D8CC File Offset: 0x0005BACC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			ModbusTcpNet.<WriteAsync>d__62 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__62();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__62>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Int16)" />
		// Token: 0x0600102E RID: 4142 RVA: 0x0005D920 File Offset: 0x0005BB20
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, short value)
		{
			ModbusTcpNet.<WriteAsync>d__63 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__63();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__63>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.UInt16)" />
		// Token: 0x0600102F RID: 4143 RVA: 0x0005D974 File Offset: 0x0005BB74
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ushort value)
		{
			ModbusTcpNet.<WriteAsync>d__64 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__64();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__64>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteMask(System.String,System.UInt16,System.UInt16)" />
		// Token: 0x06001030 RID: 4144 RVA: 0x0005D9C8 File Offset: 0x0005BBC8
		[DebuggerStepThrough]
		public Task<OperateResult> WriteMaskAsync(string address, ushort andMask, ushort orMask)
		{
			ModbusTcpNet.<WriteMaskAsync>d__65 <WriteMaskAsync>d__ = new ModbusTcpNet.<WriteMaskAsync>d__65();
			<WriteMaskAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteMaskAsync>d__.<>4__this = this;
			<WriteMaskAsync>d__.address = address;
			<WriteMaskAsync>d__.andMask = andMask;
			<WriteMaskAsync>d__.orMask = orMask;
			<WriteMaskAsync>d__.<>1__state = -1;
			<WriteMaskAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteMaskAsync>d__65>(ref <WriteMaskAsync>d__);
			return <WriteMaskAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Int16)" />
		// Token: 0x06001031 RID: 4145 RVA: 0x0005DA24 File Offset: 0x0005BC24
		[DebuggerStepThrough]
		public virtual Task<OperateResult> WriteOneRegisterAsync(string address, short value)
		{
			ModbusTcpNet.<WriteOneRegisterAsync>d__66 <WriteOneRegisterAsync>d__ = new ModbusTcpNet.<WriteOneRegisterAsync>d__66();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteOneRegisterAsync>d__66>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.UInt16)" />
		// Token: 0x06001032 RID: 4146 RVA: 0x0005DA78 File Offset: 0x0005BC78
		[DebuggerStepThrough]
		public virtual Task<OperateResult> WriteOneRegisterAsync(string address, ushort value)
		{
			ModbusTcpNet.<WriteOneRegisterAsync>d__67 <WriteOneRegisterAsync>d__ = new ModbusTcpNet.<WriteOneRegisterAsync>d__67();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteOneRegisterAsync>d__67>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		// Token: 0x06001033 RID: 4147 RVA: 0x0005DACC File Offset: 0x0005BCCC
		private OperateResult<bool[]> ReadBoolHelper(string address, ushort length, byte function)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, function);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				List<bool> list = new List<bool>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content[i], (ushort)this.softIncrementCount.GetCurrentValue()));
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<bool[]>(operateResult2);
					}
					OperateResult<byte[]> operateResult3 = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						return OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					int length2 = (int)operateResult.Content[i][4] * 256 + (int)operateResult.Content[i][5];
					list.AddRange(SoftBasic.ByteToBoolArray(operateResult3.Content, length2));
				}
				result = OperateResult.CreateSuccessResult<bool[]>(list.ToArray());
			}
			return result;
		}

		/// <summary>
		/// 批量读取线圈或是离散的数据信息，需要指定地址和长度，具体的结果取决于实现，如果富文本地址不指定，默认使用的功能码是 0x01<br />
		/// To read coils or discrete data in batches, you need to specify the address and length. The specific result depends on the implementation. If the rich text address is not specified, the default function code is 0x01.
		/// </summary>
		/// <param name="address">数据地址，比如 "1234" </param>
		/// <param name="length">数据长度</param>
		/// <returns>带有成功标识的bool[]数组</returns>
		// Token: 0x06001034 RID: 4148 RVA: 0x0005DBE2 File Offset: 0x0005BDE2
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 1);
		}

		/// <summary>
		/// 向线圈中写入bool数组，返回是否写入成功，如果富文本地址不指定，默认使用的功能码是 0x0F<br />
		/// Write the bool array to the coil, and return whether the writing is successful. If the rich text address is not specified, the default function code is 0x0F.
		/// </summary>
		/// <param name="address">要写入的数据地址，比如"1234"</param>
		/// <param name="values">要写入的实际数组</param>
		/// <returns>返回写入结果</returns>
		// Token: 0x06001035 RID: 4149 RVA: 0x0005DBF0 File Offset: 0x0005BDF0
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, values, this.Station, this.AddressStartWithZero, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <summary>
		/// 向线圈中写入bool数值，返回是否写入成功，如果富文本地址不指定，默认使用的功能码是 0x05，
		/// 如果你的地址为字地址，例如100.2，那么将使用0x16的功能码，通过掩码的方式来修改寄存器的某一位，需要Modbus服务器支持，否则写入无效。<br />
		/// Write bool value to the coil and return whether the writing is successful. If the rich text address is not specified, the default function code is 0x05.
		/// If your address is a word address, such as 100.2, then you will use the function code of 0x16 to modify a bit of the register through a mask. 
		/// It needs Modbus server support, otherwise the writing is invalid.
		/// </summary>
		/// <param name="address">要写入的数据地址，比如"12345"</param>
		/// <param name="value">要写入的实际数据</param>
		/// <returns>返回写入结果</returns>
		// Token: 0x06001036 RID: 4150 RVA: 0x0005DC6C File Offset: 0x0005BE6C
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, value, this.Station, this.AddressStartWithZero, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		// Token: 0x06001037 RID: 4151 RVA: 0x0005DCE8 File Offset: 0x0005BEE8
		[DebuggerStepThrough]
		private Task<OperateResult<bool[]>> ReadBoolHelperAsync(string address, ushort length, byte function)
		{
			ModbusTcpNet.<ReadBoolHelperAsync>d__72 <ReadBoolHelperAsync>d__ = new ModbusTcpNet.<ReadBoolHelperAsync>d__72();
			<ReadBoolHelperAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolHelperAsync>d__.<>4__this = this;
			<ReadBoolHelperAsync>d__.address = address;
			<ReadBoolHelperAsync>d__.length = length;
			<ReadBoolHelperAsync>d__.function = function;
			<ReadBoolHelperAsync>d__.<>1__state = -1;
			<ReadBoolHelperAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadBoolHelperAsync>d__72>(ref <ReadBoolHelperAsync>d__);
			return <ReadBoolHelperAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06001038 RID: 4152 RVA: 0x0005DD44 File Offset: 0x0005BF44
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			ModbusTcpNet.<ReadBoolAsync>d__73 <ReadBoolAsync>d__ = new ModbusTcpNet.<ReadBoolAsync>d__73();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<ModbusTcpNet.<ReadBoolAsync>d__73>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean[])" />
		// Token: 0x06001039 RID: 4153 RVA: 0x0005DD98 File Offset: 0x0005BF98
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			ModbusTcpNet.<WriteAsync>d__74 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__74();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__74>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean)" />
		// Token: 0x0600103A RID: 4154 RVA: 0x0005DDEC File Offset: 0x0005BFEC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			ModbusTcpNet.<WriteAsync>d__75 <WriteAsync>d__ = new ModbusTcpNet.<WriteAsync>d__75();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusTcpNet.<WriteAsync>d__75>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600103B RID: 4155 RVA: 0x0005DE3E File Offset: 0x0005C03E
		public override string ToString()
		{
			return string.Format("ModbusTcpNet[{0}:{1}]", this.IpAddress, this.Port);
		}

		// Token: 0x0400043A RID: 1082
		private byte station = 1;

		// Token: 0x0400043B RID: 1083
		private readonly SoftIncrementCount softIncrementCount;

		// Token: 0x0400043C RID: 1084
		private bool isAddressStartWithZero = true;
	}
}
